<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录界面</title>
    <link rel="stylesheet" href="../assets/css/style.css">
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
    <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../assets/css/login.css">
    
</head>
<body>
    <div class="login">
        <div class="login-content">
            <!-- 头像 -->
            <div class="login-top">
                <img src="../uploads/avatar.jpg" alt="">
            </div>


            <!-- 表单 -->
            <form>
                <div class="form-group">
                  <!-- <label for="exampleInputEmail1">Email address</label> -->
                  <input type="email" class="form-control" id="exampleInputEmail1" placeholder="邮箱">
                </div>
                <div class="form-group">
                  <!-- <label for="exampleInputPassword1"></label> -->
                  <input type="password" class="form-control" id="exampleInputPassword1" placeholder="密码">
                </div>
                <button type="button" class="btn btn-default">登录</button>
              </form> 
        </div>
    </div>
</body>
    @@include('../common/base.html')
<!-- <script src="../assets/vendors/jquery/jquery.js"></script>
<script src="../assets/vendors/bootstrap/js/bootstrap.js"></script> -->
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script> -->
<script>
  $(function () {
    $('.btn.btn-default').click(function () {
      console.log("=====");
      const email = $('#exampleInputEmail1').val()
      const pwd = $('#exampleInputPassword1').val()

      if (!email && !email.trim()) {
        alert('请输入邮箱')
        return
      }
      if (!pwd && !pwd.trim()) {
        alert('请输入密码') 
        return
      }
      const paramt = {
        email,
        password: pwd
      }

      // 登录请求
      $.ajax(`${baseUrl}/login`, {
        type: 'POST',
        data: paramt,
        success: function (res) {
          console.log("登录成功：", res);
          if (res.token) {
            // 判断token是否存在
            // 将密钥存放在localStorage
            localStorage.setItem('token', res.token)
            location.href = '/admin/index.html'
          }else {
            alert('登陆失败')
          }
        },
        error: function (err) {
          alert('登陆失败')
          console.log('登陆失败：',err);
        }
      })
    })
    
  })
</script>
</html>